package com.song.oscsong.fragment;

import org.apache.http.Header;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.song.oscsong.R;
import com.song.oscsong.adapter.NewsAdapter;
import com.song.oscsong.adapter.TweetAdapter;
import com.song.oscsong.api.OSCChinaApi;
import com.song.oscsong.bean.NewsList;
import com.song.oscsong.bean.TweetsList;
import com.song.oscsong.utils.XmlUtils;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class TweetsFragment extends Fragment {

	
private ListView mListView;
	
	private String[] datas ={"2222222","22222","222222","22222"};
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View v = inflater.inflate(R.layout.fragment_pull_refresh_listview, container ,false);
		mListView = (ListView) v.findViewById(R.id.listview);
//		NewsAdapter newsAdapter = new NewsAdapter(datas);
//		mListView.setAdapter(newsAdapter);
		OSCChinaApi.getTweetList(0, 0, new AsyncHttpResponseHandler() {
			
			@Override
			public void onSuccess(int arg0, Header[] arg1, byte[] data) {
				
				String str = new String(data);
				System.out.println(str);
				TweetsList tweetsList =  XmlUtils.toBean(TweetsList.class, data);
				
				TweetAdapter adapter = new TweetAdapter(tweetsList.getList());
				mListView.setAdapter(adapter);
				
			}
			
			@Override
			public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
				// TODO Auto-generated method stub
				
			}
		});
		return v;
		
	}
	
}
